<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class LogBalance extends Model
{
    protected $table = 'log_balance';

    protected $fillable = [
        'user_id',              #用户ID
        'user_balance',         #用户当前余额
        'action',               #动作：充值进账、消费支出
        'amount',               #交易金额
        'remarks',              #备注
    ];

    const TOP_UP = 'top_up';

    const CONSUME = 'consume';

    const WITHDRAW = 'withdraw';

    const REFUND = 'refund';

    static $ACTION_MAP = [
        self::TOP_UP => '充值',
        self::WITHDRAW => '提現',
        self::CONSUME => '消費',
        self::REFUND => '退款',
    ];

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id')->withDefault();
    }
}
